<!DOCTYPE html>
<!--[if IE 9]>         <html class="no-js lt-ie10" lang="en"> <![endif]-->
<!--[if gt IE 9]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
    <meta charset="utf-8">

    <title>数字币对冲平台|BDS虚拟币对冲平台</title>
    <#include "../static/top.ftl" >

        </head>
<body>
<!-- Page Wrapper -->
<!-- In the PHP version you can set the following options from inc/config file -->
<!--
    Available classes:

    'page-loading'      enables page preloader
-->
<div id="page-wrapper" class="page-loading">
    <!-- Preloader -->
    <!-- Preloader functionality (initialized in js/app.js) - pageLoading() -->
    <!-- Used only if page preloader enabled from inc/config (PHP version) or the class 'page-loading' is added in #page-wrapper element (HTML version) -->
    <div class="preloader">
        <div class="inner">
            <!-- Animation spinner for all modern browsers -->
            <div class="preloader-spinner themed-background hidden-lt-ie10"></div>

            <!-- Text for IE9 -->
            <h3 class="text-primary visible-lt-ie10"><strong>Loading..</strong></h3>
        </div>
    </div>

    <div id="page-container" class="header-fixed-top sidebar-visible-lg-full sidebar-light">
        <!-- Alternative Sidebar -->

        <!-- END Alternative Sidebar -->

        <!-- Main Sidebar -->



        <#include "../static/menu.ftl" >


            <!-- END Main Sidebar -->

            <!-- Main Container -->
            <div id="main-container">
                <!-- Header -->



                <#include "../static/header.ftl" >
                    <!-- END Header -->

                    <!-- Page content -->
                    <div id="page-content">
                        <!-- Validation Header -->
                        <div class="content-header">
                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="header-section">
                                        <h1>汇率设置</h1>
                                    </div>
                                </div>
                                <div class="col-sm-6 hidden-xs">
                                    <div class="header-section">
                                        <ul class="breadcrumb breadcrumb-top">
                                            <li>User Interface</li>
                                            <li>Forms</li>
                                            <li><a href="">Validation</a></li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- END Validation Header -->

                                <!-- Table Styles Block -->
                                <div class="block">
                                    <!-- Table Styles Title -->
                                    <div class="block-title clearfix">
                                        <!-- Changing classes functionality initialized in js/pages/tablesGeneral.js -->
                                        <div class="block-options pull-right">
                                            <a href="javascript:void(0)" class="btn btn-effect-ripple btn-default active" id="style-striped" data-toggle="tooltip" title=".table-striped">Striped</a>
                                            <a href="javascript:void(0)" class="btn btn-effect-ripple btn-default" id="style-condensed" data-toggle="tooltip" title=".table-condensed">Condensed</a>
                                            <a href="javascript:void(0)" class="btn btn-effect-ripple btn-default" id="style-hover" data-toggle="tooltip" title=".table-hover">Hover</a>
                                        </div>
                                        <div class="block-options pull-right">
                                            <div id="style-borders" class="btn-group">
                                                <a href="javascript:void(0)" class="btn btn-effect-ripple btn-default" id="style-default" data-toggle="tooltip">Default</a>
                                                <a href="javascript:void(0)" class="btn btn-effect-ripple btn-default active" id="style-bordered" data-toggle="tooltip" title=".table-bordered">Bordered</a>
                                                <a href="javascript:void(0)" class="btn btn-effect-ripple btn-default" id="style-borderless" data-toggle="tooltip" title=".table-borderless">Borderless</a>
                                            </div>
                                        </div>
                                        <h2><span class="hidden-xs">货币</span> 汇率表</h2>
                                    </div>
                                    <!-- END Table Styles Title -->

                                    <!-- Table Styles Content -->
                                    <div class="table-responsive">
                                        <table id="general-table" class="table table-striped table-bordered table-vcenter">
                                            <thead>
                                            <tr>
                                                <th>货币/人民币</th>
                                                <th>汇率</th>
                                                <th>人民币/货币</th>
                                                <th>反向汇率</th>
                                                <th style="width: 180px;" class="text-center"><label class="csscheckbox csscheckbox-primary"><input type="checkbox"><span></span></label><span style="margin-left: 5px">联网获取</span></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <#list pairs as pair>
                                                <tr id="${pair.id}">
                                                    <#--货币/人民币-->
                                                    <td><strong>${pair.pair_name}</strong></td>
                                                    <#--汇率-->
                                                    <#if pair.useUserVal==false>
                                                        <td><input id="${pair.id}_val" type="text" value="${pair.real_time_val}" class="form-control" readonly/></td>
                                                    </#if>
                                                    <#if pair.useUserVal==true>
                                                        <td><input id="${pair.id}_val" type="text" value="${pair.update_val}" class="form-control"/></td>
                                                    </#if>
                                                    <#--人民币/货币-->
                                                    <td><strong>${pair.re_pair_name}</strong></td>
                                                    <#--反向汇率-->
                                                    <#if pair.useUserVal==false>
                                                        <td><input id="${pair.id}_reval" type="text" value="${pair.re_real_time_val}" class="form-control" readonly/></td>
                                                    </#if>
                                                    <#if pair.useUserVal==true>
                                                        <td><input id="${pair.id}_reval" type="text" value="${pair.re_update_val}" class="form-control"/></td>
                                                    </#if>
                                                    <#if pair.useUserVal==false>
                                                        <td class="text-center"><label class="csscheckbox csscheckbox-primary"><input type="checkbox" onchange="network('${pair.id}',this)" id="${pair.id}_cbox" checked ><span></span></label></td>
                                                    </#if>
                                                    <#if pair.useUserVal==true>
                                                        <td class="text-center"><label class="csscheckbox csscheckbox-primary"><input type="checkbox" onchange="network('${pair.id}',this)" id="${pair.id}_cbox"><span></span></label></td>
                                                    </#if>
                                                </tr>
                                            </#list>
                                            <tr>
                                                <td colspan="5"><center><button type="button" id="btn_submit" class="btn btn-effect-ripple btn-primary center-block" style="margin-top: 10px">保存</button></center></td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <!-- END Table Styles Content -->
                                </div>
                                <!-- END Table Styles Block -->
                    </div>
                    <!-- END Page Container -->
            </div>
            <!-- END Page Wrapper -->


        <!-- Load and execute javascript code used only in this page -->
        <script src="/res/js/pages/uiTables.js"></script>
        <script>$(function(){ UiTables.init(); });</script>
</body>
<script type="text/javascript">
    var pairs_caches=new Array();
    $(function () {
        //原始汇率缓存
        <#list pairs as pair>
            pairs_caches.push(JSON.stringify({"id":'${pair.id}',"real_time_val":'${pair.real_time_val}',"re_real_time_val":'${pair.re_real_time_val}'}))
        </#list>
        <#--汇率修改提交-->
        $("#btn_submit").click(function(){
            var not_checked=new Array();
            //查找没被勾选的项
            for(var i=0;i<pairs_caches.length;i++) {
                var obj=JSON.parse(pairs_caches[i])
                var pid=obj['id'];
                var check_ele=document.getElementById(pid+"_cbox");
                var val_ele=""
                var reval_ele=""
                var useUserVal=false
                if(check_ele.checked==false){
                    useUserVal=true
                    val_ele=document.getElementById(pid+"_val").value;
                    reval_ele=document.getElementById(pid+"_reval").value;
                }else{
                    useUserVal=false
                    val_ele=""
                    reval_ele=""
                }
                var obj={"id":pid,"update_val":val_ele,"re_update_val":reval_ele,"useUserVal":useUserVal}
                not_checked.push(JSON.stringify(obj))
            }
            $.ajax({
                url: 'http://localhost:8087/exchange_rate_submit',
                data: { "data": "["+not_checked.toString()+"]"},
                cache: false,
                //async: false,
                type: "POST",
                dataType: 'jsonp',
                jsonp: "jsonpCallback",
                //其中success_jsonpCallback为自定义名称，与后台保持一致即可
                jsonpCallback: "success_jsonpCallback",
                success: function (result) {
                    alert(result.msg)
                }
            });
        });
    });


    function  network(id,ele) {
        var val_ele=document.getElementById(id+"_val");
        var reval_ele=document.getElementById(id+"_reval");
        if(ele.checked){//联网获取
            for(var i=0;i<pairs_caches.length;i++) {
                var pair=JSON.parse(pairs_caches[i]);
                if (id == pair['id']) {
                    val_ele.value = pair.real_time_val
                    reval_ele.value = pair.re_real_time_val
                    val_ele.readOnly = true;
                    reval_ele.readOnly = true;
                    return;
                }
            };
        }else{//联网获取
            val_ele.readOnly=false;
            reval_ele.readOnly=false;
        }
    }

</script>
</html>